<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\User;
use App\Models\User as UserModel;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Admin;
use App\Admin\Actions\Grid\User\ReviewBatchAction;

class UserreviewController extends AdminController
{

    protected $translation = 'user';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new User(), function (Grid $grid) {

            $grid->model()->with('agent')->where('state','=',UserModel::STATE_REVIEW);
            if(Admin::user()->isRole('agent')){
                $grid->model()->where('agent_id','=',Admin::user()->id);
            }
            $grid->model()->orderByDesc('id');

            $grid->column('id');
            if(Admin::user()->isRole('administrator')) {
                //$grid->column('agent.name', trans('user.fields.agent_name'));
            }
            //$grid->column('tiktokid');
            $grid->column('tiktokno');
            //$grid->column('nickname');
            $grid->column('avatar')->image('',50,50);
            $grid->column('shoptype')->display(function ($var){
                return UserModel::SHOPTAYES[$var];
            });
            $grid->column('shopname');
            $grid->column('shopdesc');
            $grid->column('identity')->display(function ($pictures) {
                return explode(",", $pictures);
            })->image('', 50, 100);

            $grid->column('review_time');

            $grid->quickSearch('nickname','tiktokno','shopname','id');
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal('tiktokno');
                $filter->equal('nickname');
                $filter->equal('shopname');
            });

            $grid->disableQuickEditButton();
            $grid->disableViewButton();
            $grid->disableCreateButton();
            $grid->disableDeleteButton();
            $grid->disableActions();
            $grid->batchActions(function (Grid\Tools\BatchActions $actions) {
                $actions->add(new ReviewBatchAction());
                $actions->disableDelete();
            });



        });
    }

}
